home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
dataval.exe
/
VALID1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-02-22
|
4KB
|
150 lines
{************************************************}
{ }
{ Turbo Pascal 6.0 }
{ Demo program from the Turbo Vision Guide }
{ }
{ Copyright (c) 1990 by Borland International }
{ }
{************************************************}
{$X+}
program TVGUID16;
uses Objects, Drivers, Views, Menus, Dialogs, App;
type
DialogData = record
InputLineData: string[128];
end;
TMyApp = object(TApplication)
constructor Init;
procedure InitStatusLine; virtual;
procedure NewDialog;
end;
PDemoDialog = ^TDemoDialog;
TDemoDialog = object(TDialog)
end;
PValidInputLine = ^TValidInputLine;
TValidInputLine = object(TInputLine)
IsValid: Boolean;
constructor Init(var Bounds: TRect; AMaxLen: Integer);
function GetPalette: PPalette; virtual;
procedure SetState(AState: Word; Enable: Boolean); virtual;
function Valid(Command: Word): Boolean; virtual;
end;
constructor TValidInputLine.Init(var Bounds: TRect; AMaxLen: Integer);
begin
TInputLine.Init(Bounds, AMaxLen);
IsValid := Valid(cmOk);
end;
function TValidInputLine.GetPalette: PPalette;
const AltPalette: String[Length(CInputLine)] = CInputLine;
begin
{ By assigning a palette index number that is out of the range of
our owner's palette, we automatically get flashing white on red
for this color entry. This should instead be mapped to an
actual palette entry in the owner... }
AltPalette[1] := #255;
if IsValid then
GetPalette := TInputLine.GetPalette
else
GetPalette := @AltPalette;
end;
procedure TValidInputLine.SetState(AState: Word; Enable: Boolean);
begin
{ If we are currently focused and AState is sfFocused, then
run a data validation... }
if ((AState and sfFocused) <> 0) and GetState(sfFocused) then
Valid(cmOk);
TInputLine.SetState(AState, Enable);
end;
function TValidInputLine.Valid(Command: Word): Boolean;
begin
if Command <> cmCancel then
begin
IsValid := (Data^ = 'Hello');
Valid := IsValid;
write(#7); { "hear" where & when Valid is called }
DrawView; { Show the new colors. }
end;
end;
var
DemoDialogData: DialogData;
{ TMyApp }
constructor TMyApp.Init;
begin
TApplication.Init;
NewDialog;
end;
procedure TMyApp.InitStatusLine;
var R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('', kbF10, cmMenu,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
nil))),
nil)
));
end;
procedure TMyApp.NewDialog;
var
Bruce: PView;
Dialog: PDemoDialog;
R: TRect;
C: Word;
begin
R.Assign(20, 6, 60, 19);
Dialog := New(PDemoDialog, Init(R, 'Demo Dialog'));
with Dialog^ do
begin
R.Assign(3, 8, 37, 9);
Bruce := New(PValidInputLine, Init(R, 128));
Insert(Bruce);
R.Assign(2, 7, 37, 8);
Insert(New(PLabel, Init(R, 'Type: Hello, then Tab around.', Bruce)));
R.Assign(15, 10, 25, 12);
Insert(New(PButton, Init(R, '~O~k', cmOK, bfDefault)));
R.Assign(28, 10, 38, 12);
Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
end;
Dialog^.SetData(DemoDialogData);
C := DeskTop^.ExecView(Dialog);
if C <> cmCancel then Dialog^.GetData(DemoDialogData);
Dispose(Dialog, Done);
end;
var
MyApp: TMyApp;
begin
with DemoDialogData do
begin
InputLineData := 'Phone home.';
end;
MyApp.Init;
MyApp.Run;
MyApp.Done;
end.